import router from '@system.router'
import storage from '@system.storage'
import fetch from '@system.fetch'
import md5 from "/src/global/md5.js";
import prompt from '@system.prompt'

async function getCategoryList(){
    let key = 'x:categoryList';
    let rt = await $xt.cget(key);
    if(rt){
        return JSON.parse(rt);
    }else{
        rt = [];
        let res = await $xt.rfetch('api/wallpaper.category');
        if(res.code === 1 && res.data){
            rt = res.data;
            $xt.cset(key,JSON.stringify(res.data));
        }
    }
    return rt; 
}
async function getrandImageList(){
    let res = await $xt.rfetch('api/wallpaper.image/rand');
    return res;
}
async function getImageList(category,page){
    let query = {page:page};
    if(category < 0){
        if(category === '-2'){
          query['is_selected'] = 1;
        }
    }else{
        query['category_id'] = category;
    }
    let res = await $xt.rfetch('api/wallpaper.image',query);
    return res;
}

export default {
    getCategoryList,getrandImageList,getImageList
}
